package zero.tech.games.gate.event;

import zero.tech.core.ZeroContext;
import zero.tech.core.event.EventListener;
import zero.tech.core.event.EventType;
import zero.tech.games.common.ForbitUtil;
import zero.tech.games.common.QueueConsts;
import zero.tech.games.common.UserOnlineUtil;
import zero.tech.games.common.gm.GmForbitUser;
import zero.tech.games.entity.games.UserOnline;
import zero.tech.redis.queue.QueueUtil;
import zero.tech.wsnet.data.NetEventType;
import zero.tech.wsnet.net.WebClient;

public class WsOpenEvent implements EventListener{

	@Override
	public EventType netEventType() {
		return NetEventType.ENGINE_WEBSOCKET_OPEN;
	}

	@Override
	public void notifyEvent(Object... objs) {
		System.out.println("大厅连接打开");
		WebClient webClient= (WebClient) objs[0];
		int uid=Integer.valueOf(webClient.getUserId());
		//检查封禁状态
		ForbitUtil forbitUtil = ZeroContext.getInstance(ForbitUtil.class);
		GmForbitUser gmForbitUser = forbitUtil.getGmForbitUser(uid);
		if(gmForbitUser!=null) {
			if("ALL".equals(gmForbitUser.getService_id())) {
				webClient.activeClose();
				return;
			}
		}
		QueueUtil queueUtil=ZeroContext.getInstance(QueueUtil.class);
		UserOnline userOnline = new UserOnline();
		userOnline.setUid(uid);
		userOnline.setOnline(1);
		queueUtil.putQueue(QueueConsts.QUEUE_ONLINE_STATUS,userOnline);
		UserOnlineUtil userOnlineUtil=ZeroContext.getInstance(UserOnlineUtil.class);
		userOnlineUtil.insert("GATE",uid);
	}

	@Override
	public boolean asynchronous() {
		return false;
	}

}
